package com.rahms.server.service;

import com.rahms.common.constant.AutoFillConstant;
import com.rahms.common.constant.CacheConstant;
import com.rahms.common.constant.JwtClaimsConstant;
import com.rahms.common.constant.MessageConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 常量服务类
 * 提供所有常量类的统一访问接口
 */
@Service
public class ConstantService {

    /**
     * 获取所有消息常量
     */
    public Map<String, String> getAllMessageConstants() {
        Map<String, String> messages = new HashMap<>();
        
        // 认证与登录相关
        messages.put("PASSWORD_ERROR", MessageConstant.PASSWORD_ERROR);
        messages.put("ACCOUNT_NOT_FOUND", MessageConstant.ACCOUNT_NOT_FOUND);
        messages.put("ACCOUNT_DISABLE", MessageConstant.ACCOUNT_DISABLE);
        messages.put("LOGIN_SUCCESS", MessageConstant.LOGIN_SUCCESS);
        messages.put("LOGOUT_SUCCESS", MessageConstant.LOGOUT_SUCCESS);
        messages.put("REGISTER_SUCCESS", MessageConstant.REGISTER_SUCCESS);
        messages.put("UNAUTHORIZED_ACCESS", MessageConstant.UNAUTHORIZED_ACCESS);
        messages.put("TOKEN_EXPIRED", MessageConstant.TOKEN_EXPIRED);
        messages.put("INVALID_TOKEN", MessageConstant.INVALID_TOKEN);
        
        // 用户管理相关
        messages.put("USER_ADD_SUCCESS", MessageConstant.USER_ADD_SUCCESS);
        messages.put("USER_UPDATE_SUCCESS", MessageConstant.USER_UPDATE_SUCCESS);
        messages.put("USER_DELETE_SUCCESS", MessageConstant.USER_DELETE_SUCCESS);
        messages.put("USER_NOT_EXIST", MessageConstant.USER_NOT_EXIST);
        messages.put("USERNAME_EXISTS", MessageConstant.USERNAME_EXISTS);
        messages.put("PHONE_EXISTS", MessageConstant.PHONE_EXISTS);
        
        // 老人信息管理相关
        messages.put("ELDERLY_ADD_SUCCESS", MessageConstant.ELDERLY_ADD_SUCCESS);
        messages.put("ELDERLY_UPDATE_SUCCESS", MessageConstant.ELDERLY_UPDATE_SUCCESS);
        messages.put("ELDERLY_DELETE_SUCCESS", MessageConstant.ELDERLY_DELETE_SUCCESS);
        messages.put("ELDERLY_NOT_EXIST", MessageConstant.ELDERLY_NOT_EXIST);
        messages.put("ELDERLY_NOT_BELONG", MessageConstant.ELDERLY_NOT_BELONG);
        
        // 药品管理相关
        messages.put("MEDICATION_ADD_SUCCESS", MessageConstant.MEDICATION_ADD_SUCCESS);
        messages.put("MEDICATION_UPDATE_SUCCESS", MessageConstant.MEDICATION_UPDATE_SUCCESS);
        messages.put("MEDICATION_DELETE_SUCCESS", MessageConstant.MEDICATION_DELETE_SUCCESS);
        messages.put("MEDICATION_NOT_EXIST", MessageConstant.MEDICATION_NOT_EXIST);
        messages.put("MEDICATION_NOT_BELONG", MessageConstant.MEDICATION_NOT_BELONG);
        
        // 用药计划相关
        messages.put("PLAN_ADD_SUCCESS", MessageConstant.PLAN_ADD_SUCCESS);
        messages.put("PLAN_UPDATE_SUCCESS", MessageConstant.PLAN_UPDATE_SUCCESS);
        messages.put("PLAN_DELETE_SUCCESS", MessageConstant.PLAN_DELETE_SUCCESS);
        messages.put("PLAN_NOT_EXIST", MessageConstant.PLAN_NOT_EXIST);
        messages.put("PLAN_ALREADY_STOPPED", MessageConstant.PLAN_ALREADY_STOPPED);
        messages.put("PLAN_CONFIRM_SUCCESS", MessageConstant.PLAN_CONFIRM_SUCCESS);
        
        // 健康数据相关
        messages.put("HEALTH_DATA_ADD_SUCCESS", MessageConstant.HEALTH_DATA_ADD_SUCCESS);
        messages.put("HEALTH_DATA_UPDATE_SUCCESS", MessageConstant.HEALTH_DATA_UPDATE_SUCCESS);
        messages.put("HEALTH_DATA_DELETE_SUCCESS", MessageConstant.HEALTH_DATA_DELETE_SUCCESS);
        messages.put("HEALTH_DATA_NOT_EXIST", MessageConstant.HEALTH_DATA_NOT_EXIST);
        
        // 消息与公告相关
        messages.put("NOTIFICATION_SEND_SUCCESS", MessageConstant.NOTIFICATION_SEND_SUCCESS);
        messages.put("NOTIFICATION_READ_SUCCESS", MessageConstant.NOTIFICATION_READ_SUCCESS);
        messages.put("NOTIFICATION_NOT_EXIST", MessageConstant.NOTIFICATION_NOT_EXIST);
        messages.put("ANNOUNCEMENT_PUBLISH_SUCCESS", MessageConstant.ANNOUNCEMENT_PUBLISH_SUCCESS);
        messages.put("ANNOUNCEMENT_UPDATE_SUCCESS", MessageConstant.ANNOUNCEMENT_UPDATE_SUCCESS);
        messages.put("ANNOUNCEMENT_DELETE_SUCCESS", MessageConstant.ANNOUNCEMENT_DELETE_SUCCESS);
        messages.put("ANNOUNCEMENT_NOT_EXIST", MessageConstant.ANNOUNCEMENT_NOT_EXIST);
        
        // 文件操作相关
        messages.put("FILE_UPLOAD_SUCCESS", MessageConstant.FILE_UPLOAD_SUCCESS);
        messages.put("FILE_UPLOAD_FAILED", MessageConstant.FILE_UPLOAD_FAILED);
        messages.put("FILE_DELETE_SUCCESS", MessageConstant.FILE_DELETE_SUCCESS);
        messages.put("FILE_NOT_EXIST", MessageConstant.FILE_NOT_EXIST);
        messages.put("FILE_FORMAT_ERROR", MessageConstant.FILE_FORMAT_ERROR);
        messages.put("FILE_SIZE_EXCEED", MessageConstant.FILE_SIZE_EXCEED);
        
        // 数据验证相关
        messages.put("PARAM_IS_NULL", MessageConstant.PARAM_IS_NULL);
        messages.put("PARAM_IS_INVALID", MessageConstant.PARAM_IS_INVALID);
        messages.put("DATA_NOT_FOUND", MessageConstant.DATA_NOT_FOUND);
        messages.put("DATA_ALREADY_EXISTS", MessageConstant.DATA_ALREADY_EXISTS);
        
        // 操作结果相关
        messages.put("OPERATION_SUCCESS", MessageConstant.OPERATION_SUCCESS);
        messages.put("OPERATION_FAILED", MessageConstant.OPERATION_FAILED);
        messages.put("SAVE_SUCCESS", MessageConstant.SAVE_SUCCESS);
        messages.put("SAVE_FAILED", MessageConstant.SAVE_FAILED);
        messages.put("DELETE_SUCCESS", MessageConstant.DELETE_SUCCESS);
        messages.put("DELETE_FAILED", MessageConstant.DELETE_FAILED);
        messages.put("UPDATE_SUCCESS", MessageConstant.UPDATE_SUCCESS);
        messages.put("UPDATE_FAILED", MessageConstant.UPDATE_FAILED);
        messages.put("QUERY_SUCCESS", MessageConstant.QUERY_SUCCESS);
        messages.put("QUERY_FAILED", MessageConstant.QUERY_FAILED);
        
        // 系统相关
        messages.put("SYSTEM_ERROR", MessageConstant.SYSTEM_ERROR);
        messages.put("NETWORK_ERROR", MessageConstant.NETWORK_ERROR);
        messages.put("DATABASE_ERROR", MessageConstant.DATABASE_ERROR);
        messages.put("SERVICE_UNAVAILABLE", MessageConstant.SERVICE_UNAVAILABLE);
        messages.put("REQUEST_TIMEOUT", MessageConstant.REQUEST_TIMEOUT);
        
        // 权限相关
        messages.put("PERMISSION_DENIED", MessageConstant.PERMISSION_DENIED);
        messages.put("ROLE_NOT_EXIST", MessageConstant.ROLE_NOT_EXIST);
        messages.put("NEED_ADMIN_ROLE", MessageConstant.NEED_ADMIN_ROLE);
        messages.put("NEED_FAMILY_ROLE", MessageConstant.NEED_FAMILY_ROLE);
        
        // 导出相关
        messages.put("EXPORT_SUCCESS", MessageConstant.EXPORT_SUCCESS);
        messages.put("EXPORT_FAILED", MessageConstant.EXPORT_FAILED);
        
        // 提醒相关
        messages.put("REMINDER_SENT", MessageConstant.REMINDER_SENT);
        messages.put("REMINDER_MISSED", MessageConstant.REMINDER_MISSED);
        messages.put("REMINDER_CONFIRMED", MessageConstant.REMINDER_CONFIRMED);
        
        return messages;
    }

    /**
     * 获取所有缓存常量
     */
    public Map<String, Object> getAllCacheConstants() {
        Map<String, Object> cacheConstants = new HashMap<>();
        
        // 缓存前缀
        cacheConstants.put("USER_CACHE_PREFIX", CacheConstant.USER_CACHE_PREFIX);
        cacheConstants.put("USER_INFO_CACHE", CacheConstant.USER_INFO_CACHE);
        cacheConstants.put("USER_LIST_CACHE", CacheConstant.USER_LIST_CACHE);
        cacheConstants.put("ELDERLY_CACHE_PREFIX", CacheConstant.ELDERLY_CACHE_PREFIX);
        cacheConstants.put("ELDERLY_INFO_CACHE", CacheConstant.ELDERLY_INFO_CACHE);
        cacheConstants.put("ELDERLY_LIST_CACHE", CacheConstant.ELDERLY_LIST_CACHE);
        cacheConstants.put("MEDICATION_CACHE_PREFIX", CacheConstant.MEDICATION_CACHE_PREFIX);
        cacheConstants.put("MEDICATION_INFO_CACHE", CacheConstant.MEDICATION_INFO_CACHE);
        cacheConstants.put("MEDICATION_LIST_CACHE", CacheConstant.MEDICATION_LIST_CACHE);
        cacheConstants.put("DRUG_PLAN_CACHE_PREFIX", CacheConstant.DRUG_PLAN_CACHE_PREFIX);
        cacheConstants.put("DRUG_PLAN_INFO_CACHE", CacheConstant.DRUG_PLAN_INFO_CACHE);
        cacheConstants.put("DRUG_PLAN_LIST_CACHE", CacheConstant.DRUG_PLAN_LIST_CACHE);
        cacheConstants.put("DRUG_PLAN_ACTIVE_CACHE", CacheConstant.DRUG_PLAN_ACTIVE_CACHE);
        cacheConstants.put("HEALTH_DATA_CACHE_PREFIX", CacheConstant.HEALTH_DATA_CACHE_PREFIX);
        cacheConstants.put("HEALTH_DATA_LIST_CACHE", CacheConstant.HEALTH_DATA_LIST_CACHE);
        cacheConstants.put("HEALTH_DATA_STATISTICS_CACHE", CacheConstant.HEALTH_DATA_STATISTICS_CACHE);
        cacheConstants.put("NOTIFICATION_CACHE_PREFIX", CacheConstant.NOTIFICATION_CACHE_PREFIX);
        cacheConstants.put("NOTIFICATION_LIST_CACHE", CacheConstant.NOTIFICATION_LIST_CACHE);
        cacheConstants.put("NOTIFICATION_UNREAD_COUNT_CACHE", CacheConstant.NOTIFICATION_UNREAD_COUNT_CACHE);
        cacheConstants.put("SYSTEM_MESSAGE_CACHE_PREFIX", CacheConstant.SYSTEM_MESSAGE_CACHE_PREFIX);
        cacheConstants.put("SYSTEM_MESSAGE_LIST_CACHE", CacheConstant.SYSTEM_MESSAGE_LIST_CACHE);
        cacheConstants.put("ANNOUNCEMENT_CACHE_PREFIX", CacheConstant.ANNOUNCEMENT_CACHE_PREFIX);
        cacheConstants.put("ANNOUNCEMENT_INFO_CACHE", CacheConstant.ANNOUNCEMENT_INFO_CACHE);
        cacheConstants.put("ANNOUNCEMENT_LIST_CACHE", CacheConstant.ANNOUNCEMENT_LIST_CACHE);
        cacheConstants.put("ANNOUNCEMENT_LATEST_CACHE", CacheConstant.ANNOUNCEMENT_LATEST_CACHE);
        cacheConstants.put("JWT_TOKEN_CACHE_PREFIX", CacheConstant.JWT_TOKEN_CACHE_PREFIX);
        cacheConstants.put("JWT_USER_CACHE_PREFIX", CacheConstant.JWT_USER_CACHE_PREFIX);
        
        // 缓存过期时间
        cacheConstants.put("CACHE_EXPIRE_SHORT", CacheConstant.CACHE_EXPIRE_SHORT);
        cacheConstants.put("CACHE_EXPIRE_MEDIUM", CacheConstant.CACHE_EXPIRE_MEDIUM);
        cacheConstants.put("CACHE_EXPIRE_LONG", CacheConstant.CACHE_EXPIRE_LONG);
        cacheConstants.put("CACHE_EXPIRE_VERY_LONG", CacheConstant.CACHE_EXPIRE_VERY_LONG);
        cacheConstants.put("JWT_TOKEN_EXPIRE", CacheConstant.JWT_TOKEN_EXPIRE);
        cacheConstants.put("USER_SESSION_EXPIRE", CacheConstant.USER_SESSION_EXPIRE);
        cacheConstants.put("STATISTICS_CACHE_EXPIRE", CacheConstant.STATISTICS_CACHE_EXPIRE);
        
        return cacheConstants;
    }

    /**
     * 获取所有JWT声明常量
     */
    public Map<String, String> getAllJwtClaimsConstants() {
        Map<String, String> jwtClaims = new HashMap<>();
        jwtClaims.put("EMP_ID", JwtClaimsConstant.EMP_ID);
        jwtClaims.put("USER_ID", JwtClaimsConstant.USER_ID);
        jwtClaims.put("PHONE", JwtClaimsConstant.PHONE);
        jwtClaims.put("USERNAME", JwtClaimsConstant.USERNAME);
        jwtClaims.put("NAME", JwtClaimsConstant.NAME);
        return jwtClaims;
    }

    /**
     * 获取所有自动填充常量
     */
    public Map<String, String> getAllAutoFillConstants() {
        Map<String, String> autoFill = new HashMap<>();
        autoFill.put("SET_CREATE_TIME", AutoFillConstant.SET_CREATE_TIME);
        autoFill.put("SET_UPDATE_TIME", AutoFillConstant.SET_UPDATE_TIME);
        autoFill.put("SET_CREATE_USER", AutoFillConstant.SET_CREATE_USER);
        autoFill.put("SET_UPDATE_USER", AutoFillConstant.SET_UPDATE_USER);
        return autoFill;
    }

    /**
     * 获取所有常量
     */
    public Map<String, Object> getAllConstants() {
        Map<String, Object> allConstants = new HashMap<>();
        allConstants.put("messages", getAllMessageConstants());
        allConstants.put("cache", getAllCacheConstants());
        allConstants.put("jwtClaims", getAllJwtClaimsConstants());
        allConstants.put("autoFill", getAllAutoFillConstants());
        return allConstants;
    }
}
